#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
@AUTHOR: tyc
@VERSION: 1.0.0
@DESCRIPTION: 
@time: 2021-06-30 22:35:53 
"""

import re

s = '''
<div class = 'qa'><span id='10012'>中国</span></div> 
<div class = 'ed'><span id='10012'>俄罗斯</span></div> 
<div class = 'cd'><span id='10012'>日本</span></div> 
<div class = 'xc'><span id='10012'>韩国</span></div> 
<div class = 'bg'><span id='10012'>美国</span></div> 
'''

# 将需要匹配的字符串整体考下来，在需要提取的地方输入以下表达式
# (?P<分组名称>正则表达式)
# re.S允许换行匹配
obj = re.compile(r"<div class = '(?P<class>.*?)'><span id='(?P<id>\d+)'>(?P<value>.*?)</span></div>", re.S)

for item in obj.finditer(s):
    print(item.group('class'))
    print(item.group('id'))
    print(item.group('value'))
